<?php


namespace app\im\model;


use app\cms\community\lib\QueryModel;
use iflow\Response;
use think\model\relation\HasOne;

class imGroupUserModel extends QueryModel
{

    protected $table = 'im_group_user_table';

    /**
     * 绑定用户组
     * @return HasOne
     */
    public function hasImGroup(): HasOne
    {
        return $this->hasOne(imGroupModel::class, 'im_group_id', 'im_group_id');
    }


    /**
     * 获取群组群员列表
     * @param int $im_group_id
     * @return Response
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getImGroupUserInfoById(int $im_group_id): Response
    {
        $info = $this->withJoin([
            'im_group_avatar' => 'im_group_avatar',
            'im_group_name' => 'im_group_name',
            'im_group_type' => 'im_group_type'
        ], 'LEFT')
        -> where([
            'im_group_id' => $im_group_id
        ])
        -> select();

        return $info
            ? message() -> success('查询成功', $info -> toArray())
            : message() -> nodata('暂无数据');
    }

}